import 'package:flutter/material.dart';
import 'package:flutter/services.dart';


class OrderPage extends StatefulWidget {
  const OrderPage({super.key});

  @override
  _OrderPageState createState() => _OrderPageState();
}
late ScrollController _scrollController;
bool showSearch = false;
class _OrderPageState extends State<OrderPage> {


  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    double width = size.width;
    double height = size.height;
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
          body: Stack(
            children: [
              Container(color: Colors.red, width: width, height: width/1.4+22,),
              ListView(
                controller: _scrollController,
                children: [
                  Column(children: [
                    Container(width: width, height: width/1.4+22,),

                    Container(color: Colors.white,height: width/3,),
                    Container(height: height-(width/3),child: Row(
                      children: [
                        Container(color: Colors.white,width: width* (1-(1/1.2)),),
                        Stack(
                          children: [
                            Positioned(child: Container(
                              color: Color.fromARGB(255, 208, 208, 208), width: width/1.2, height: height,
                              child: ListView(
                                children: [
                                  Container(color: Colors.cyan,height: 120,),
                                  Container(color: Colors.amber,height: 120,),
                                  Container(color: Colors.cyan,height: 120,),
                                  Container(color: Colors.amber,height: 120,),
                                  Container(color: Colors.cyan,height: 120,),
                                  Container(color: Colors.amber,height: 120,),
                                  Container(color: Colors.cyan,height: 120,),
                                  Container(color: Colors.amber,height: 120,),
                                  Container(color: Colors.cyan,height: 120,),
                                  Container(color: Colors.amber,height: 120,),
                                  Container(color: Colors.cyan,height: 120,),
                                  Container(color: Colors.amber,height: 120,),

                                ],
                              ),
                            ),
                            ),

                          ],
                        ),
                      ],
                    ),)


                  ],)
                ],
              ),
              Positioned(top: 50, child: Visibility(visible: showSearch, child: Container(color: Colors.white24, width: width, height: width/10,),),),
              Positioned(top: 50, left: width/4, child: Visibility(visible: showSearch, child: Container(color: Color.fromARGB(255, 208, 208, 208), width: width/2, height: width/10,),),),
            ],)
      ),
    );
  }


  @override
  void dispose() {
    _scrollController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    _scrollController = ScrollController();
    setState(() {
      showSearch = false;
    });

    //监听listview的当前Offset位置
    _scrollController.addListener(() {
      // 获取ListView的当前滚动偏移量
      double offset = _scrollController.offset;
      // 在这里可以处理滚动位置的变化，例如打印滚动偏移量
      print("ListView当前滚动位置：$offset");

        if (offset < 270) {
          setState(() {
            showSearch = false;
          });
        } else {
          setState(() {
            showSearch = true;
          });
        }

    });

    super.initState();
  }
}